const { DataTypes } = require('sequelize')

module.exports = (sequelize) => {
  const TableConfig = sequelize.define('TableConfig', {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    table_id: {
      type: DataTypes.STRING(50),
      allowNull: false,
      unique: true,
      comment: '表格唯一标识'
    },
    name: {
      type: DataTypes.STRING(100),
      allowNull: false,
      comment: '表格名称'
    },
    description: {
      type: DataTypes.TEXT,
      comment: '表格描述'
    },
    table_name: {
      type: DataTypes.STRING(100),
      allowNull: false,
      comment: '数据库表名'
    },
    default_page_size: {
      type: DataTypes.INTEGER,
      defaultValue: 10,
      comment: '默认分页大小'
    },
    searchable_columns: {
      type: DataTypes.JSON,
      comment: '可搜索列'
    },
    sortable_columns: {
      type: DataTypes.JSON,
      comment: '可排序列'
    },
    filterable_columns: {
      type: DataTypes.JSON,
      comment: '可筛选列'
    },
    export_enabled: {
      type: DataTypes.BOOLEAN,
      defaultValue: true,
      comment: '是否支持导出'
    },
    batch_operations: {
      type: DataTypes.JSON,
      comment: '批量操作列表'
    },
    status: {
      type: DataTypes.ENUM('active', 'inactive'),
      defaultValue: 'active',
      comment: '状态'
    },
    created_by: {
      type: DataTypes.INTEGER,
      comment: '创建者ID'
    }
  }, {
    tableName: 'table_configs',
    comment: '动态表格配置表'
  })

  return TableConfig
}